#
#        Python GUI - Radio Buttons - Swing
#

import javax.swing as swing
from GRadioButtons import RadioButton as GRadioButton
from StdFonts import system_font
from JHacks import *
from Controls import to_html,from_html,_j_ActionCallback

class RadioButton(GRadioButton):
    
    def __init__(self, title="Button", font=system_font, **kwds):
        self._just=kwds.get("just","left")
        self._title=title
        self._j_obj=swing.JRadioButton(to_html(title,self._just))
        
        self._actioncallback=_j_ActionCallback(self)
        self._j_obj.addActionListener(self._actioncallback)
        
        GRadioButton.__init__(self,title=title,font=font,**kwds)
    
    def trigger(self):
        if self.group:
            self.group._value=self.value
            self.group.do_action()
    
    def set_title(self,title):
        self._title=title
        self._j_obj.setText(to_html(title,self._just))
    
    def get_title(self):
        return self._j_obj.getText()
    
    def get_just(self):
        return self._just
    
    def set_just(self,just):
        self._just=just
        self._j_obj.setText(to_html(self._title,self._just))
    
    def _value_changed(self):
        if self.group:
            del self.group._value_dict[self.value]
            self.group._value_dict[value]=self
    
    def destroy(self):
        self.group=None
        GRadioButton.destroy(self)
    
    

